<template>
	<view>
		<view class="u-skeleton">
			<view class="step">
				<counseling-step class="u-skeleton-fillet" :stepOptions="stepOptions"></counseling-step>
			</view>
			<!-- <view class="question">
				<view class="title">你想咨询哪方面的问题？</view>
				<view class="list">
					<button :class="['btn', 'u-skeleton-fillet', {current: current === index}]" type="default" v-for="(item, index) in btns" :key="item.id" @click="handleBtnClick(index)">{{ item.val }}</button>
				</view>
			</view> -->
			<view class="input-question">
				<view class="title">简单描述一下问题</view>
				<view class="uni-textarea">
					<textarea class="text u-skeleton-fillet" placeholder-style="color:#5b5e67" placeholder="方便律师更快为您解答"/>
				</view>
			</view>
			<view class="telephone">
				<view class="item">
					<view class="name u-skeleton-fillet">参考价格</view>
					<view class="phone u-skeleton-fillet" style="padding-right: 4rpx;">¥300起</view>
				</view>
				<view class="item">
					<view class="name u-skeleton-fillet">服务订金</view>
					<view class="phone u-skeleton-fillet" style="color: #eb6657;padding-right: 4rpx;">¥30</view>
				</view>
				<view class="item">
					<view class="name u-skeleton-fillet">联系方式</view>
					<!-- <view class="phone u-skeleton-fillet">15806084632</view> -->
					<input class="phone uni-input u-skeleton-fillet" placeholder="请输入电话" placeholder-style="font-size: 28rpx;" v-model="form.mobile" />
				</view>
				<view class="item">
					<view class="name u-skeleton-fillet">电话咨询</view>
					<view class="price u-skeleton-fillet">
						<view style="display: none;">限时免费</view>
						<view style="display: none;">¥30</view>
						<view>¥{{ priceInfo.price }}/30分钟</view>
					</view>
				</view>
			</view>
			<view class="btn-con" v-show="!loading">
				<!-- <my-button @click.native="pay">确认下单</my-button> -->
				<my-button :btnDisabled="btnDisabled" @btnClick="btnClick">确认下单</my-button>
			</view>
			<popup-pay :popShow="popShow" :money="money" @closePopup="closePopup" @confirmPay="confirmPay"></popup-pay>
		</view>
		<u-skeleton :loading="loading" el-color="#eee" bg-color="#fff" :animation="true"></u-skeleton>
	</view>
</template>

<script>
	import counselingStep from '../../components/counseling-step/counseling-step.vue'
	import myButton from '../../components/button/button.vue'
	import popupPay from '../../components/popup-pay/popup-pay.vue'
	import { createOrder, orderPay, createOrderPrice } from '@/api/orderApi.js'
	export default {
		data() {
			return {
				btnDisabled: false,
				loading: true, // 是否显示骨架屏组件
				current: -1,
				stepOptions: [
					{
						step: 1,
						val: '支付订单',
						show: true
					},
					{
						step: 2,
						val: '律师接单',
						show: true
					},
					{
						step: 3,
						val: '开始咨询',
						show: false
					},
				],
				btns: [
					{
						id: 1,
						val: '婚姻家事'
					},
					{
						id: 2,
						val: '房产纠纷'
					},
					{
						id: 3,
						val: '公司工商'
					},
					{
						id: 4,
						val: '交通事故'
					},
					{
						id: 5,
						val: '合同纠纷'
					},
					{
						id: 6,
						val: '债权纠纷'
					},
					{
						id: 7,
						val: '劳动用工'
					},
					{
						id: 8,
						val: '刑事辩护'
					},
					{
						id: 9,
						val: '行政复议'
					},
					{
						id: 10,
						val: '行政诉讼'
					},
					{
						id: 11,
						val: '其他'
					}
				],
				popShow: false,
				form: {
					mobile: uni.getStorageSync('user').member.mobile || '',
					description: ''
				},
				options: {},
				orderId: '',
				money: {} ,// 弹出的余额和价格
				priceInfo: {} // 价格信息
			}
		},
		onLoad(options) {
			this.options = options
			this._createOrderPrice()
		},
		methods: {
			async _createOrderPrice() {
				const res = await createOrderPrice({team_id: this.options.team-0 || '', type: this.options.type -0})
				console.log(res)
				this.priceInfo = res.data.data
				setTimeout(() => {
					this.loading = false
				}, 300)
			},
			handleBtnClick(index) {
				if (this.current === index) return
				console.log(index)
				this.current = index
			},
			async confirmPay(e) {
				console.log(e)
				this.popShow = e.popShow
				uni.showLoading({title: '加载中...'})
				const res = await orderPay({id: this.orderId-0, paytype: e.paymentWay})
				console.log(res)
				if (res.data.data.price == 0) return uni.navigateTo({url: '/pages/order/pay-success?orderId='+this.orderId})
				// #ifdef APP-PLUS
				if (e.paymentWay === 3) {
					// 微信支付
					this.$utils.appWxPay(res.data.data.appConfig, (success)=> {
						console.log(success)
						uni.navigateTo({url: '/pages/order/pay-success?orderId='+this.orderId})
					}, (error) => {
						console.log(error)
					})
				} else if (e.paymentWay === 2) {
					console.log('支付宝支付')
				} else if (e.paymentWay === 1) {
					console.log('余额支付')
					uni.navigateTo({url: '/pages/order/pay-success?orderId=' + res.data.data.id})
				}
				// #endif
			},
			closePopup(data) {
				console.log(data)
				this.popShow = data
				this.btnDisabled = false
			},
			async btnClick(val) {
				if (!this.form.mobile) return uni.showToast({title: '请填写电话',icon: 'none'})
				uni.showLoading({title: '加载中...'})
				this.btnDisabled = val // 禁止确认下单按钮
				let data = {
					type: this.options.type-0,
					mobile: this.form.mobile,
					description: this.form.description,
					team_id: this.options.team ? this.options.team-0 : '',
				}
				const res = await createOrder(data)
				console.log(res)
				this.money = res.data.data.order
				this.money.paytypes = res.data.data.paytypes
				this.orderId = res.data.data.order.id
				this.popShow = true
			}
		},
		components: {
			counselingStep,
			myButton,
			popupPay
		}
	}
</script>

<style lang="scss">
	.step {
		padding: 40rpx 0;
	}
	.question {
		.title {
			font-size: 34rpx;
			color: #2c313c;
			font-weight: bold;
			padding: 20rpx 30rpx 30rpx;
		}
		.list {
			display: flex;
			flex-wrap: wrap;
			.btn {
				width: 150rpx;
				height: 70rpx;
				line-height: 70rpx;
				font-size: 28rpx;
				padding: 0;
				border-radius: 6rpx;
				border: 1rpx solid #fff;
				background-color: #ebecf0;
				color: #5b5e67;
				margin: 0;
				margin-right: 30rpx;
				margin-bottom: 20rpx;
				&:active {
					opacity: 0.8;
				}
				&:after {
					border: none;
				}
			}
			.btn:nth-child(4),.btn:nth-child(8) {
				margin-right: 0;
			}
			.btn:nth-child(1),.btn:nth-child(5),.btn:nth-child(9){
				margin-left: 30rpx;
			}
			.current {
				background-color: #0d2647;
				color: #fff;
				transition: all 0.2s ease;
			}
		}
	}
	.input-question {
		.title {
			font-size: 34rpx;
			color: #2c313c;
			font-weight: bold;
			padding: 20rpx 30rpx 30rpx;
		}
		.text {
			font-size: 28rpx;
			height: 184rpx;
			width: 648rpx;
			background-color: #ebecf0;
			border-radius: 6rpx;
			padding: 28rpx 20rpx;
			margin: 0 auto;
		}
	}
	.telephone {
		margin: 40rpx 30rpx 0;
		background-color: #ebecf0;
		border-radius: 6rpx;
		.item {
			display: flex;
			align-items: center;
			height: 99rpx;
			margin: 0 22rpx;
			border-bottom: 1rpx solid #e6e6e6;
			border-radius: 0.5rpx;
			.name {
				font-size: 28rpx;
				color: #5b5e67;
			}
			.phone {
				font-size: 28rpx;
				color: #5b5e67;
				margin-left: auto;
				text-align: right;
			}
			.price {
				margin-left: auto;
				display: flex;
				align-items: center;
				view:nth-child(1) {
					font-size: 24rpx;
					color: #7a5507;
					padding: 7rpx 14rpx;
					background-color: #d9b975;
					border-radius: 12rpx 0rpx 12rpx 12rpx;
				}
				view:nth-child(2) {
					font-size: 22rpx;
					color: #adafb5;
					padding: 0 8rpx;
				}
				view:nth-child(3) {
					font-size: 28rpx;
					color: #eb6657;
				}
			}
			&:last-child {
				border-bottom: none;
			}
		}
	}
	.btn-con {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}
</style>
